package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.itheima.dao.PathogenyDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Pathogeny;
import com.itheima.utils.GetRowsConditionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author ${小帅帅}
 * @date 2019-11-03
 * 病因知识库的服务
 */
@Service(interfaceClass = PathogenyService.class)
@Transactional
public class PathogenyServiceImpl implements PathogenyService {
    @Autowired
    private PathogenyDao pathogenyDao;


    //批量导入病因知识库
    @Override
    public void pathogenyAdd(List<Pathogeny> pathogenyList) {

        if (pathogenyList != null && pathogenyList.size() > 0) {

            //遍历预约的数据，进行识别判断
            for (Pathogeny paList : pathogenyList) {

                //持久层：根据病因，查询是否已经进行了导入
                long count = pathogenyDao.countPathogeny(paList.getLoreID());
                //判断
                if (count > 0) {

                    //查询持久层：当前数据库中存在，已经设置，则直接进行覆盖更新
                    pathogenyDao.overridePathogeny(paList);
                } else {

                    //查询持久层：当前数据库中没有该日期，直接进行插入存储即可
                    pathogenyDao.pathogenyAdd(paList);
                }

            }
        }
    }


    //病因知识库的分页查询
    @Override
    public PageResult findPage(QueryPageBean pageBean) throws Exception {
        //使用工具类，获取分页查询的条件
        String condition = GetRowsConditionUtils.getCondition(pageBean);

        //持久层：权限管理分页查询调用
        Page<Pathogeny> page = pathogenyDao.findPage(condition);

        //获取总记录数
        long total = page.getTotal();

        //获取当前页的显示结果
        List<Pathogeny> rows = page.getResult();

        //传递参数，并返回
        return new PageResult(total, rows);

    }

    //病因生病类型图形报表
    @Override
    public List<Map<String,Object>> find() {

        List< Map<String,Object> > list=pathogenyDao.find();

        return list;
    }


}
